
<template>
  <main-container :headerText="'会员管理 >> 添加 ' + (isEdit ? '编辑' : '添加')">
    <div class="content" :key="showPageKey">
  <div class="edit-wrap">
    <div class="top-input">
      
  <div class="item">
    <label for>
      <span class="tips">* </span>操作人：
    </label>
    <div class="inline-block">
      <el-input 
            v-model="formData.operator" 
            placeholder="请输入操作人" 
            size="small"
            style="width: 220px;"
            
            
            ></el-input>
    </div>
  </div>
  
  <div class="item img-item"
    
    >
    <label for>
      <span class="tips">* </span>打款凭据：
    </label>
    <div class="inline-block">
      
            <upload-img 
              labelName= "打款凭据" 
              :imgArrProp="formData.evidence"
              :countLimit="3"
              @uploadSuccess="handleUploadBanner"
            />
          
    </div>
  </div>
  
    </div>
  </div>
  
  <div class="submit-option">
    <el-button v-if="!isEdit" @click="handleAdd" size="small" type="primary">添加</el-button>
    <el-button v-else @click="handleEdit" size="small" type="primary">保存</el-button>
    <el-button @click="handleCancel" size="small" type="primary">取消</el-button>
  </div>
  </div>
  </main-container>
</template>


<script>
import jhTools from "@/utils/jhTools"; //工具函数
import API from "@/utils/api_config.js"; //引入api

import main_container from '@/components/main_container';
import top_option from "@/components/subCon/topOption";
import date_edit from "@/components/subEditCon/dateEdit";
import upload_img from "@/components/subEditCon/uploadImgEdit";
import bg_editor from "@/components/bg-editor";

export default {
  components: {
    "main-container": main_container,
    "top-option": top_option,
    // "input-edit": () => resolve(["@/components/subEditCon/inputEdit"]),
    // "select-edit": () => resolve(["@/components/subEditCon/selectEdit"]),
    "date-edit": date_edit,
    "upload-img": upload_img,
    "bg-editor": bg_editor,
  },
  props: {},
  data() {
    return {
        showPageKey: 119, //刷新的key
      formData: {
    operator: "",
        evidence: "",
        },
  
      
      isEdit: false,
      allMethods: "",
    };
  },
  mounted() {
    this.allMethods = this.getAllMethods();
    
    
    const id = this.$route.query.id;
    //有id获取编辑数据
    if (id) {
      this.getEditData(id);
      this.isEdit = true;
    }

    // //测试test
    // this.formData.testImgStr = "https://honcollar.oss-cn-shenzhen.aliyuncs.com/file/a3ae8023-d02a-4f3b-9ce5-f5fcd33f1b96.jpg?Expires=1912753798&OSSAccessKeyId=LTAI4FyZ6LRvk2FLjYuRQU1N&Signature=E2EAngZwKqN7QdBBWmUyD5KwZAM%3D,https://honcollar.oss-cn-shenzhen.aliyuncs.com/file/bad5ad4d-5c21-443e-86b8-a407dec6b99f.jpg?Expires=1912753798&OSSAccessKeyId=LTAI4FyZ6LRvk2FLjYuRQU1N&Signature=zYE6gfTWbYyP2QUse%2BZqceX3iKU%3D,https://honcollar.oss-cn-shenzhen.aliyuncs.com/file/8fdd60e0-77af-4aa1-a82e-3087faf9cbc5.jpg?Expires=1912753798&OSSAccessKeyId=LTAI4FyZ6LRvk2FLjYuRQU1N&Signature=gbXVuVghSP9iEcmMbDV4haKHljU%3D,https://honcollar.oss-cn-shenzhen.aliyuncs.com/file/74d2f8ca-564e-4184-af9d-f66f0df36017.jpg?Expires=1912753799&OSSAccessKeyId=LTAI4FyZ6LRvk2FLjYuRQU1N&Signature=0Oru0%2BjoKUNrMVr%2Bjh8rFd1Kqts%3D,https://honcollar.oss-cn-shenzhen.aliyuncs.com/file/1e0280cd-fcab-4103-bf20-1fa7d91dd1c1.jpg?Expires=1912753799&OSSAccessKeyId=LTAI4FyZ6LRvk2FLjYuRQU1N&Signature=sbcX8v22frNg%2BC4rbhqvk6LRAk8%3D";
  },
  methods: {
    
    //添加
    handleAdd () {
      let url = API.financial_m.user_zhuan_zhang;
      
  //非空校验
  var dataRes = jhTools.checkInputFormDataTool({
    tThis: this,
    dataArr: [
      "operator",
        "evidence",
        
    ],
    tipsObj: {
      "operator": "操作人",
        "evidence": "打款凭据",
        
    }
  });
  if(!dataRes) {
    return;
  }
  
      
      var {
            operator,
        evidence,
        
      } = this.formData;

      let data = {
            operator,
        evidence,
        
         courseId: Number(this.$route.query.courseId), 
      };
     
      console.log("参数", data);
      jhTools.post(
        url,
        data,
        null,
        (res) => {
          console.log("结果", res);
          if (res.code == "200") {
            this.$message({
              type: "success",
              message: "操作成功!",
            });
            this.$router.push({
              path: "/course_manager_course_chapter",
              query:  { id: this.$route.query.courseId } 
            });
          } else {
            this.$message({
              type: "warning",
              message: res.message,
            });
          }
        },
        (err) => {
          console.log(err);
        }
      );
    },
  
  //获取数据
  getEditData(id) {
    let url = API.financial_m.detail + "?id=" + id; 
    const param = {
      id,
      
    };
    console.log("详情", param);
    jhTools.get(
      url,
       
        param,
        null,
      (res) => {
        console.log("获取数据详情", res);
        if(res.code == 200) {
          
    let formData = {};
  formData.operator = res.data.operator ? res.data.operator + "" : "";
    formData.evidence = res.data.evidence ? res.data.evidence + "" : "";
    
          

          this.formData = formData;
          setTimeout(()=> {
            this.showPageKey = 110;  //更新视图
          }, 300);
        }
      },
      (err) => {
        console.log(err);
      }
    );
  },
  
    //编辑提交
    handleEdit () {

      
  //非空校验
  var dataRes = jhTools.checkInputFormDataTool({
    tThis: this,
    dataArr: [
      "operator",
        "evidence",
        
    ],
    tipsObj: {
      "operator": "操作人",
        "evidence": "打款凭据",
        
    }
  });
  if(!dataRes) {
    return;
  }
  
      

      let url = API.financial_m.user_zhuan_zhang
      let id = this.$route.query.id;
      
      var {
            operator,
        evidence,
        
      } = this.formData;

      let data = { 
        id,
            operator,
        evidence,
        
        
       };
      console.log("参数", data);
      jhTools.post(
        url,
        data,
        null,
        (res) => {
          console.log("结果", res);
          if (res.code == 200) {
            this.$message({
              type: "success",
              message: "操作成功!",
            });
            this.$router.push({
              path: "/financial_m_extract_table",
              query: {}
            });
          } else {
            //提示
            this.$message({
              type: "warning",
              message: res.message,
            });
          }
          
        },
        (err) => {
          console.log(err);
        }
      );
    },
  
            //图片上传
            handleUploadBanner (imgArrStr) {
              this.formData.evidence = imgArrStr;
            },
          

    //取消返回
    handleCancel () {
      this.$router.go(-1);
    },

    /* 方法抽离集合 */
    getAllMethods() {
      var _this = this;
      return {
        
      };
    },
  },
};
</script>

<style lang="scss" scoped>
// @import '~styles/mixins.scss';
// @import '~styles/variables.scss';



/* 操作栏相关*/

.content {
  min-height: 100%;
}

.top-option {
  min-height: 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #fff;
  border-bottom: 1px solid #efefef;
  margin: 0 30px;
  padding: 10px 0;

  .left-box {
    padding-left: 30px;
    max-width: 900px;

    .sub {
      float: left;
      width: 200px;
      margin-left: 10px;
      margin-top: 10px;
    }
  }

  .right-box {
    padding-right: 30px;
    // min-width: 300px;

    .sub {
      float: right;
      margin-left: 10px;
      margin-top: 10px;
    }
  }
}

/* 操作栏相关*/

/* 输入*/
.edit-wrap {
  padding: 40px;
  border-radius: 10px;
  background-color: #fff;
  font-size: 14px;

  label {
    display: inline-block;
    width: 120px;
    text-align: right;
  }
  .tips {
    color: #f10215;
  }
  // //标题
  // .title {
  //   height: 46px;
  //   font-size: 14px;
  //   padding-left: 20px;
  //   font-weight: bold;
  //   line-height: 46px;
  // }

  .top-input {
    .item {
      margin-top: 20px;

      &.img-item {
        display: flex;
        flex-direction: row;
        // margin-bottom: -36px;

        .inline-block {
          max-height: 160px;

        }
      }

    }
  }

  //标题描述类
  .title-text {
    font-size: 15px;
    line-height: 22px;
    padding-left: 30px;
  }
}


.submit-option {
  width: 300px;
  padding-top: 80px;
  padding-bottom: 60px;
  padding-left: 100px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.clearfix::after {
  content: "";
  display: table;
  clear: both;
}

//调整element 样式
.inline-block {
  display: inline-block;
  margin-left: 22px;
  &.id {
    padding-left: 20px;
  }
  el-input {
    width: 20px !important;
  }

  //单项选择
   .radio-box {
      // width: 70px;
      display: inline-block;
      text-align: left;
    }
    .radio-box:nth-child(1) {
      // margin-left: -40px;
    }
}

/* 上传按钮样式*/
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  border: 1px solid #ddd;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 107px;
  height: 107px;
  line-height: 107px;
  text-align: center;
  border: 1px solid #ddd;
  border-radius: 6px;
}
.avatar {
  width: 107px;
  height: 107px;
  display: block;
}
</style>